package front.end.subestacao.itens;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

public class Subestacao implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private List<Painel> paineis;

	private String nome;
	
	public Subestacao(String nome) {
		this.nome = nome;
		
		this.paineis = new LinkedList<Painel>();
	}

	
	public List<Painel> getPaineis() {
		return paineis;
	}

	public void setPaineis(List<Painel> paineis) {
		this.paineis = paineis;
	}
	
	public void addPainel(Painel painel){
		if(this.paineis.isEmpty()){
			this.setPainelComoAtivo(painel);
		}
		this.paineis.add(painel);
	}
	
	public void setPainelComoAtivo(Painel painel){
		
		for(Painel p: paineis){
			if(p.getAtivo()){
				p.setAtivo(false);
			}
		}
		painel.setAtivo(true);
		
	}
	
	public Painel getPainelAtivo()
	{
		for(Painel p: paineis){
			if(p.getAtivo()){
				return p;
			}
		}
		return null;
	}


	public String getNome() {
		return nome;
	}


	public void setNome(String nome) {
		this.nome = nome;
	}

	
	public Boolean existePainelNome(String nome){
		for(Painel painel: this.paineis){
			if(painel.getNome().equals(nome)){
				return true;
			}
		}
		return false;
	}
	
}
